package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.window.NxWindowEvent;

	/**
	 * 帮派战报名逻辑 
	 * @author liuel
	 * 
	 */	
	public class FactionBattleSignLogic
	{
		private static var _self			:FactionBattleSignLogic;
		private var _model					:ModelLocator;
		private var _ui					:FactionBattleSignUI;
		public static function getInstance():FactionBattleSignLogic
		{
			if(_self == null)
			{
				_self = new FactionBattleSignLogic();
			}
			return _self;
		}
		public function FactionBattleSignLogic()
		{
		}
		public function Init() : void
		{
			_model		= ModelLocator.getInstance();
			_ui			= FactionBattleSignUI.getInstance();
			//打开界面
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ON_OPEN_GUILD_FIGHT_SIGNUP_UI),getInfo);
			InitUI();
		}
		public function	BeforeShow():void
		{
			addEvent();
			setpic();
		}
		private function setpic():void
		{
			if(_ui.pic.source == null)
			{
				_ui.pic.source = ResPath.JPG+"Faction"+".jpg";
			}
		}
		public function	AfterHide():void
		{
			removeEvent();
		}
		private function getInfo(e:CustomMsgEvent=null):void
		{
			var num:int 	=e.pList[0]; //报名数
			var state:int	=e.pList[1]; //自己在帮派的职位  1 帮主 2 副帮主  3帮众
			var isSign:int	=e.pList[2]; //自己帮派报名状态
			var str:String;
			isSign ==0? str = "":str=StaticIni.getSwfLangStr("GuildUIStr_21");
			_ui.numLabel.htmlText =StaticIni.getSwfLangStrVar("GuildUIStr_20",[num])+str;
			if(isSign == 1)
			{
				setBtn(3);
			}
			else
			{
				setBtn(state);
			}
			if(_ui.created == false)
			{
				_ui.showOrHide();
			}
		}
		private function setBtn(val:int):void
		{
			_ui.suqnBtn.visible = false;
			if(val ==1 || val ==2)
			{
				_ui.suqnBtn.visible = true;
			}
		}
		private function InitUI():void
		{
			_ui.infoLabel.htmlText 	=StaticIni.getSwfLangStr("GuildUIStr_17");
			_ui.bagLabel1.htmlText	=StaticIni.getSwfLangStr("GuildUIStr_18");
			_ui.bagLabel2.htmlText	=StaticIni.getSwfLangStr("GuildUIStr_19");
		}
		private function addEvent():void
		{
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onColse);
			_ui.lookBtn.addEventListener(MouseEvent.CLICK,onClickLook);
			_ui.suqnBtn.addEventListener(MouseEvent.CLICK,onClicksuqn);
			
			_ui.bagLabel1.addEventListener(MouseEvent.MOUSE_OVER, onShowTips1);
			_ui.bagLabel2.addEventListener(MouseEvent.MOUSE_OVER, onShowTips2);
			
			_ui.bagLabel1.addEventListener(MouseEvent.MOUSE_OUT, onHide);
			_ui.bagLabel2.addEventListener(MouseEvent.MOUSE_OUT, onHide);
		}
		private function removeEvent():void
		{
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onColse);
			_ui.lookBtn.removeEventListener(MouseEvent.CLICK,onClickLook);
			_ui.suqnBtn.removeEventListener(MouseEvent.CLICK,onClicksuqn);
			
			_ui.bagLabel1.addEventListener(MouseEvent.MOUSE_OVER, onShowTips1);
			_ui.bagLabel2.addEventListener(MouseEvent.MOUSE_OVER, onShowTips2);
			
			_ui.bagLabel1.addEventListener(MouseEvent.MOUSE_OUT, onHide);
			_ui.bagLabel2.addEventListener(MouseEvent.MOUSE_OUT, onHide);
		}
		private function onColse(e:NxWindowEvent):void
		{
			_ui.hide();
		}
		private function onShowTips1(e:MouseEvent):void
		{
			var str:String = StaticIni.getSwfLangStr("GuildUIStr_31");
			TipsMainLogic.instance.showString(str);
		}
		private function onShowTips2(e:MouseEvent):void
		{
			var str:String = StaticIni.getSwfLangStr("GuildUIStr_32");
			TipsMainLogic.instance.showString(str);
		}
		private function onHide(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * 点击报名查看 
		 * @param e
		 * 
		 */		
		private function onClickLook(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GUILDFIGHT_GET_SIGNUP_LIST);
			_ui.hide();
		}
		/**
		 *报名 
		 * @param e
		 * 
		 */		
		private function onClicksuqn(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GUILDFIGHT_SIGNUP);
		}
	}
}